package org.arain.spring.captive.portal.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.arain.spring.captive.portal.utils.EhcacheUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import top.zhaoyuliu.summer.common.utils.AppUtils;

/**
 *
 * @author Arain
 * @date 2019年6月28日 下午12:45:53
 */
public class Interceptor implements HandlerInterceptor {

	private EhcacheUtil ehcacheUtil;
	
	
	public Interceptor(EhcacheUtil ehcacheUtil) {
		this.ehcacheUtil = ehcacheUtil;
	}



	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String ipAddr = AppUtils.getIpAddr(request);
		Object object = ehcacheUtil.get("timeCache", ipAddr);
		if (null == object) {
			response.sendRedirect("/portal");
			return false;
		}
		return true;
	}

}
